#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include "file_interface.h"
#include <iostream>
#include <stdint.h>
#include <string>
#include <boost/thread.hpp>

namespace egear{namespace file{ // egear::file

class SuspenseFile;

class FileManagerInterface {
    /*
     * handle all files in a transmittion.
     * It can contain several files
     */
public:
    FileManagerInterface();
    virtual ~FileManagerInterface();
    /*
     * run the file manager as a function.
     * to be use in boost.thread.
     */
    virtual void operator()()=0;
    virtual void openFiles()=0;
    virtual void closeFiles()=0;
    virtual std::string read(int pieceId, int64_t offset)=0;
    virtual int write(int pieceId, int64_t offset,const std::string &data)=0;
protected:
    boost::condition_variable cond;
};

class CurlFileManager:public FileManagerInterface {
    /*
     * File manager for files without checksum.
     * like file in HTTP or FTP transmittion.
     * TODO
     */
public:
    CurlFileManager(std::string _folder, 
		    std::vector<std::string> _files);
    ~CurlFileManager();
    void openFiles();
    void closeFiles();
    virtual int resize(int pieceId, int64_t _size);
    std::string read(int pieceId, int64_t offset)=0;
    int write(int pieceId, int64_t offset,const std::string &data)=0;
protected:
    std::string folder;
    std::vector<SyncSuspenseFile*> files;
};

class TorrentFileManager:public FileManagerInterface {
    /*
     * for bittorrent
     * TODO
     */
};

}} // egear::file

#endif /* FILE_MANAGER_H */
